Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 11371 - Number theory for newbies / 11371.cpp
blob5c5b738e7a36c9415bd278b93f6c90324e321944
1 #include <iostream>
2 #include <algorithm>
3 #include <vector>
4 #include <cassert>
6 using namespace std;
8 int main(){
9 string s;
10 while (getline(cin, s)){
11 assert(s[0] != '0');
12 vector<int> v(s.size());
13 for (int i=0; i<s.size(); ++i) v[i] = s[i] - '0';
14 sort(v.begin(), v.end(), greater<int>() );
16 long long int a = 0;
17 for (int i=0; i<v.size(); ++i){
18 a*= 10; a += v[i];
21 sort(v.begin(), v.end());
22 if (v[0] == 0)
23 for (int i=1; i<v.size(); ++i){
24 if (v[i] != 0){
25 swap(v[0], v[i]);
26 break;
30 long long int b = 0;
31 for (int i=0; i<v.size(); ++i){
32 b*= 10; b += v[i];
35 printf("%lld - %lld = %lld = 9 * %lld\n", a, b, a-b, (a-b)/9);
38 return 0;